﻿package com.lhk.appframework.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class UtilsFile {
	private UtilsFile()
	{
		/* cannot be instantiated */
		throw new UnsupportedOperationException("cannot be instantiated");
	}
	
	
	
	
	// 从路径获取文件名
 	public static String getFileName(String pathandname){ 
 		int start=pathandname.lastIndexOf("/");  
         int end=pathandname.lastIndexOf(".");  
         if(start!=-1 && end!=-1){  
             return pathandname.substring(start+1,end);    
         }else{  
             return null;  
         }             
 	}
 	
 	//把Stream转换成String
 	public static String convertStreamToString(InputStream is) {
 		BufferedReader reader = new BufferedReader(new InputStreamReader(is));
			StringBuilder sb = new StringBuilder();
			String line = null;

			try {
				while ((line = reader.readLine()) != null) {
					sb.append(line + "/n");
				}
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return sb.toString();	
 	}
}
